package com.bang.study.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @Auther: Bang
 * @Date: 2020/7/29 23:12
 * @Description:
 */
public class LifeCode implements BeanPostProcessor,InitializingBean, DisposableBean {

    private Integer version;

    private String name;

    public LifeCode() {
        System.out.println("LifeCode Constructor =============");
    }


    public void init() {
        System.out.println("LifeCode init =================");
    }

    public void destory() {
        System.out.println("LifeCode destory =================");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("LifeCode PostConstruct =================");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("LifeCode PreDestroy =================");
    }


    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "LifeCode{" +
                "version=" + version +
                ", name='" + name + '\'' +
                '}';
    }


    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("LifeCode postProcessBeforeInitialization ==============");
        return bean;
    }


    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("LifeCode postProcessAfterInitialization ==============");
        return bean;
    }


    public void afterPropertiesSet() throws Exception {
        System.out.println("LifeCode afterPropertiesSet <<<<<<<<<<<<<<<<");
    }

    public void destroy() throws Exception {
        System.out.println("LifeCode destroy <<<<<<<<<<<<<<<<");
    }
}
